/*
 * InvertedListSerializerTest_gtest.h
 *
 *  Created on: Nov 29, 2012
 *      Author: m
 */

#ifndef INVERTEDLISTRECORDLISTSERIALIZERTEST_GTEST_H_
#define INVERTEDLISTRECORDLISTSERIALIZERTEST_GTEST_H_

#include <gtest/gtest.h>
#include <cstring>

#include "../physical_layer/file_system/InvertedList.h"
#include "../physical_layer/file_system/InvertedListRecord.h"
#include "../physical_layer/serializers/InvertedListRecordListSerializer.h"


using physical::InvertedList;
using physical::InvertedListRecordListSerializer;
using physical::InvertedListRecord;
using physical::InvertedListRecordList;

class InvertedListRecordListSerializerTestFixture: public ::testing::Test
{
public:
    InvertedListRecordListSerializerTestFixture() :
            m_serializer()
    {
        // initialization code here
    }

    void SetUp()
    {
        // code here will execute just before the test ensues
    }

    void TearDown()
    {
        // code here will be called just after the test completes
        // ok to through exceptions from here if need be
    }

    ~InvertedListRecordListSerializerTestFixture()
    {
        // cleanup any pending stuff, but no exceptions allowed
    }

    // put in any custom data members that you need
    InvertedListRecordListSerializer m_serializer;
};

TEST_F ( InvertedListRecordListSerializerTestFixture, serializeDeserializeSequencialLists )
{
    InvertedList invertedList = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    InvertedList invertedList2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };

    InvertedListRecord ilRecord (5, invertedList);
    InvertedListRecord ilRecord2 (7, invertedList2);

    InvertedListRecordList recordList;

    recordList.push_back(ilRecord);
    recordList.push_back(ilRecord2);

    InvertedListRecordList deserializedRecordList;

    size_t expectedSerializationBytes;
    size_t serializedBytes;
    size_t deserializedBytes;
    byte buffer[128];

    expectedSerializationBytes = m_serializer.getSize( recordList );

    serializedBytes = m_serializer.serialize( recordList, buffer );

    deserializedBytes = m_serializer.deserialize( buffer, deserializedRecordList );

    ASSERT_EQ( deserializedRecordList.front(), ilRecord );

    ASSERT_EQ( deserializedRecordList.back(), ilRecord2 );

    ASSERT_EQ( expectedSerializationBytes, serializedBytes );

    ASSERT_EQ( expectedSerializationBytes, deserializedBytes );

}



#endif /* INVERTEDLISTRECORDLISTSERIALIZERTEST_GTEST_H_ */
